package com.zfj.HashSet;

import java.util.HashSet;
import java.util.Iterator;

/**
 * @author zfj
 * @date 2022/3/7 -11:45
 * HashSet使用
 * 存储结构：哈希表(数组+链表+红黑树)
 */
public class Demo1 {
	public static void main(String[] args) {
		HashSet<String> hashSet=new HashSet<>();
		//添加元素
		hashSet.add("张三");
		hashSet.add("李四");
		hashSet.add("王五");
		hashSet.add("赵六");
//		hashSet.add("张三");
		System.out.println(hashSet.size());
		System.out.println(hashSet.toString());
		//删除
		hashSet.remove("张三");
		System.out.println(hashSet.size());
		//遍历
		//增强for
		System.out.println("=========增强for=========");
		for (String s : hashSet) {
			System.out.println(s);
		}
		//迭代器
		System.out.println("===迭代器============");
		Iterator<String> iterator = hashSet.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		//判断
		System.out.println(hashSet.contains("郭富城"));
		System.out.println(hashSet.isEmpty());
	}
}
